﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MovieBrowser.Controller;
using MovieBrowser.Model;
using MovieBrowser.Presentation.Events;

namespace MovieBrowser.Presentation.Viewer
{
    public partial class MovieStatusBar : UserControl, IDebugLogEvent, IWebNavigateEvent, ISearchMovieEvent, IMoviePersonalNoteChangeEvent
    {
        private bool _detailsView;

        public bool DetailsView
        {
            get { return _detailsView; }
            set
            {
                statusFull.Visible = value;
                statusShort.Visible = !value;
                _detailsView = value;

                if (_detailsView)
                {
                    statusFull.LoadMovie(statusShort.SelectedMovie);
                }
                else
                {
                    statusShort.LoadMovie(statusFull.SelectedMovie);
                }
            }
        }

        public MovieBrowserController Controller
        {
            set
            {
                statusShort.Controller = value;
                statusFull.Controller = value;
            }
        }

        public MovieStatusBar()
        {
            InitializeComponent();
            DetailsView = true;

            statusFull.DebugText += statusFull_DebugText;
            statusFull.NavigateWeb += statusFull_NavigateWeb;
            statusFull.MovieSearch += statusFull_MovieSearch;
            statusFull.NoteChange += statusFull_NoteChange;

            statusShort.DebugText += statusFull_DebugText;
            statusShort.NavigateWeb += statusFull_NavigateWeb;
            statusShort.MovieSearch += statusFull_MovieSearch;
            statusShort.NoteChange += statusFull_NoteChange;

        }

        void statusFull_NoteChange(object sender, EventArgs e)
        {
            if (NoteChange != null)
                NoteChange(sender, e);
        }

        void statusFull_MovieSearch(object sender, EventArgs e)
        {
            if (MovieSearch != null)
                MovieSearch(sender, e);
        }

        void statusFull_NavigateWeb(object sender, EventArgs e)
        {
            if (NavigateWeb != null)
                NavigateWeb(sender, e);
        }

        void statusFull_DebugText(object sender, EventArgs e)
        {
            if (DebugText != null)
                DebugText(sender, e);
        }

        public event EventHandler DebugText;
        public event EventHandler NavigateWeb;
        public event EventHandler MovieSearch;
        public event EventHandler NoteChange;

        public void LoadMovie(Movie movie)
        {
            if (DetailsView)
            {
                statusFull.LoadMovie(movie);
            }
            else
            {
                statusShort.LoadMovie(movie);
            }
        }

        public void LoadUserList()
        {
            if (DetailsView)
            {
                statusFull.LoadUserList();
            }
        }
    }
}
